import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:ride_rex/main/mine/follow_list/mine_follow_list_logic.dart';
import 'package:ylm_ui_kit/ylm_ui_kit.dart';

class MineFollowListPage extends GetView<MineFollowListLogic> {
  const MineFollowListPage({super.key});

  @override
  Widget build(BuildContext context) {
    return BaseScaffold(
      titleStr: 'Follow List',
      scaffoldBackgroundColor: Colors.white,
      child: GetBuilder<MineFollowListLogic>(
        init: MineFollowListLogic(),
        builder: (logic) {
          return logic.getRefresh(
            child: ListView.separated(
              itemCount: logic.dataList.length,
              itemBuilder: (BuildContext context, int index) {
                return MineFollowListItem(logic.dataList[index]);
              },
              separatorBuilder: (BuildContext context, int index) => const SizedBox(),
            ),
          );
        },
      ),
    );
  }
}

class MineFollowListItem extends StatelessWidget {
  const MineFollowListItem(this.bean, {super.key});

  final MineFollowListBean bean;

  @override
  Widget build(BuildContext context) {
    return CommonListItemScaffold(
      contentPadding: EdgeInsets.symmetric(horizontal: 21.w, vertical: 16.w),
      left: _buildAvatar(),
      center: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _buildName(),
          _buildAge().paddingTop(8.w),
        ],
      ).paddingHorizontal(10.w).expanded(),
      right: _buildUnblock(),
    );
  }

  Widget _buildAvatar() {
    return ImageWidget.url(bean.avatarUrl ?? '', width: 44.w, height: 44.w, radius: 44.w);
  }

  Widget _buildName() {
    return TextWidget.oneLine(text: bean.nickname, fontSize: 14, color: '#404040'.toColor);
  }

  Widget _buildAge() {
    return TextWidget.oneLine(
      text: '${bean.age} ${bean.country}',
      fontSize: 12,
      color: Colors.black.withOpacity(0.6),
    );
  }

  Widget _buildUnblock() {
    return ButtonWidget.text(
      'Unfollow',
      alignment: Alignment.center,
      height: 26.w,
      width: 71.w,
      fontSize: 12,
      textColor: '#CCCCCC'.toColor,
      backgroundColor: '#F2F2F2'.toColor,
      onTap: () {
        Get.find<MineFollowListLogic>().unfollow(bean.userId ?? '');
      },
      hasInkWell: false,
      borderRadius: 26.w,
    );
  }
}
